<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.visibility == 'hidden')
          e.style.visibility = 'visible';
       else
          e.style.visibility = 'hidden';
    }
//-->
</script>
<table width="100%">
<tr>
  <td width="50%">
    <table width="100%">
      <tr align="center">
        <td width="20%"><a href="/user"><img src="/images/home_icon_small.png" border="0" style="vertical-align:middle;"/></a><br/>Home</td>
        <td width="20%"><a href="/game_runnings/gamepanel_a?gencode=<%=@gencode%>"><img src="/images/monitor_icon.png" border="0" style="vertical-align:middle;"/></a><br/>Panel A</td>
        <td width="20%"><a href="/game_runnings/gamepanel?gencode=<%=@gencode%>"><img src="/images/monitor_icon.png" border="0" style="vertical-align:middle;"/></a><br/>Panel B</td>
        <td width="20%"><a href="/game_runnings/summary?gencode=<%=@gencode%>"><img src="/images/summary_icon.jpg" border="0" style="vertical-align:middle;"/></a><br/>Summary</td>
        <td><a href="/game_runnings/setting_parameter?gencode=<%=@gencode%>"><img src="/images/inventory_icon.jpg" border="0" style="vertical-align:middle;"/></a><br/>Setting</td>
      </tr>
    </table>
  </td>
  <td width="2%">&nbsp;</td>
  <td>
    <span style="background-color: green; width:350px; font-size: 2em; color:white; vertical-align:middle;">
    Year: <span id="yearpanel"><%=@game.current_year%></span>
    &nbsp;&nbsp;&nbsp;
    Round: <span id="roundpanel"><%=@game.current_round%></span>
    </span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <%if @game.run_flag=='N'%>
    <img src="/images/stop_icon.jpg" width="50px" style="vertical-align:middle;"/>
    <%else%>
    <img src="/images/start_icon.gif" width="50px" style="vertical-align:middle;"/>
    <%end%>
  </td>
</tr>
</table>
<br/>
<center><a href="/game_runnings/trophy?gencode=<%=@gencode%>" target="_blank"><img src="/images/trophy.png" border="0"/></a></center>
<br/>
<span style="font-size:25px; color:red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Equity Per Share ที่ถูกต้องจะแสดงเมื่อจบการซื้อขายในแต่ละปี</span>
<center>
<%if @game.run_flag=='N'%>
  <table width="100%">
    <tr>
      <td align="center">
        <input type="button" value="Show 'A' Result" onclick="toggle_visibility('a_area');"/>
        <div id="a_area" style="visibility:hidden;">
        <table width="100%" style="border: 3px solid black; font-size: 20px;">
          <tr align="center" style="border: 3px solid black;" bgcolor="#cccccc">
            <th>Player</th>
            <th>Level</th>
            <th>Units Sold</th>
            <th>Revenue</th>
            <th>Average Price</th>
            <th>EqPS</th>
          </tr>
          <%@a_players.each do |p|%>
          <tr align="right">
            <td align="left"><a href="/user/show_board/<%=p.gencode%>?year=<%=@game.current_year-1%>" target="_blank"><%=p.name.gsub('Group ','')%></a></td>
            <td><%=p.level%></td>
            <%
      #        sold = Sale.sum(:quantity, :conditions=>["game_id=? AND year=? AND player_id=?", @game.id, @game.current_year-1, p.id])
      #        revenue = Sale.sum(:cash, :conditions=>["game_id=? AND year=? AND player_id=?", @game.id, @game.current_year-1, p.id])
              pb = PlayerBalance.find(:first, :conditions=>["player_id=? AND year=?", p.id, @game.current_year-1])
            %>
            <td><%=number_with_delimiter(pb.sold_unit)%></td>
            <td><%=number_with_delimiter(pb.sold)%></td>
            <td><%begin%><%=number_with_precision(pb.sold.to_f/pb.sold_unit, :precision=>2)%><%rescue%><%end%></td>
            <td><%begin%><%=number_with_precision(pb.equity_per_share, :precision=>2)%><%rescue%><%end%></td>
          </tr>
          <%end%>
        </table>
        </div>
      </td>
      <td align="center">
        <input type="button" value="Show 'B' Result" onclick="toggle_visibility('b_area');"/>
        <div id="b_area" style="visibility:hidden;">
        <table width="100%" style="border: 3px solid black; font-size: 20px;">
          <tr align="center" style="border: 3px solid black;" bgcolor="#cccccc">
            <th>Player</th>
            <th>Level</th>
            <th>Units Sold</th>
            <th>Revenue</th>
            <th>Average Price</th>
            <th>EqPS</th>
          </tr>
          <%@b_players.each do |p|%>
          <tr align="right">
            <td align="left"><a href="/user/show_board/<%=p.gencode%>?year=<%=@game.current_year-1%>" target="_blank"><%=p.name.gsub('Group ','')%></a></td>
            <td><%=p.level%></td>
            <%
      #        sold = Sale.sum(:quantity, :conditions=>["game_id=? AND year=? AND player_id=?", @game.id, @game.current_year-1, p.id])
      #        revenue = Sale.sum(:cash, :conditions=>["game_id=? AND year=? AND player_id=?", @game.id, @game.current_year-1, p.id])
              pb = PlayerBalance.find(:first, :conditions=>["player_id=? AND year=?", p.id, @game.current_year-1])
            %>
            <td><%=number_with_delimiter(pb.sold_unit)%></td>
            <td><%=number_with_delimiter(pb.sold)%></td>
            <td><%begin%><%=number_with_precision(pb.sold.to_f/pb.sold_unit, :precision=>2)%><%rescue%><%end%></td>
            <td><%begin%><%=number_with_precision(pb.equity_per_share, :precision=>2)%><%rescue%><%end%></td>
          </tr>
          <%end%>
        </table>
        </div>
      </td>
    </tr>
  </table>
<%else%>
  <table width="90%" style="border: 3px solid black; font-size: 30px;">
    <tr align="center" style="border: 3px solid black;" bgcolor="#cccccc">
      <th>Player</th>
      <th>Level</th>
      <th>Units Sold</th>
      <th>Revenue</th>
      <th>Average Price</th>
    </tr>
    <%@players.each do |p|%>
    <tr align="right">
      <td align="left"><%=p.name%></td>
      <td><%=p.level%></td>
      <%
        sold = Sale.sum(:quantity, :conditions=>["game_id=? AND year=? AND round<=? AND player_id=?", @game.id, @game.current_year, @game.current_round, p.id])
        revenue = Sale.sum(:cash, :conditions=>["game_id=? AND year=? AND round<=? AND player_id=?", @game.id, @game.current_year, @game.current_round, p.id])
      %>
      <td><%=number_with_delimiter(sold)%></td>
      <td><%=number_with_delimiter(revenue)%></td>
      <td><%begin%><%=number_with_precision(revenue/sold, :precision=>2)%><%rescue%><%end%></td>
    </tr>
    <%end%>
  </table>
<%end%>
  <a href="/game_runnings/print_all_player?gencode=<%=@gencode%>&year=<%=@game.current_year-1%>" target="_blank">View All</a>
</center>